package exercise05;

public class Vehicle {
    public double speed;
    public double maxSpeed;
    public double weight;

    //构造函数
    public Vehicle(double maxSpeed, double weight) {
        speed = 0;
        this.maxSpeed = maxSpeed;
        this.weight = weight;
    }

    //构造函数
    public Vehicle() {
        speed = 0;
        maxSpeed = 150.0;
        weight = 3.2;
    }

    //启动
    public void run(double speed) {
        if (speed > maxSpeed){
            speed = maxSpeed;
        }
        this.speed=speed;
        System.out.println("车辆正在运行，速度为："+speed);
    }

    //停止
    public void stop() {
        this.speed=0;
        System.out.println("车辆停止，速度为："+speed);
    }

    //启动停止输出
    public void runStop(double speed){
        System.out.println("初始属性\n"+this);
        this.run(speed);
        System.out.println(this);
        this.stop();
        System.out.println(this);
        System.out.println("===========================");
    }

    @Override
    public String toString() {
        return "Vehicle{" +
                "speed=" + speed +
                ", maxSpeed=" + maxSpeed +
                ", weight=" + weight +
                '}';
    }
}
